﻿using System;
using System.Collections.Generic;
using Autodesk.Revit.DB;
using HYRevitCode.XYZUtility;
using Teigha.Core;
using Teigha.TD;

namespace QuickModel.InteractiveOperation
{
	public class TextInfo : TextCadElement
	{
		public Category RevitLayer { get; set; }

		public ImportInstance HostImportIns { get; }

		public bool IsAttribute { get; }

		public string UseCadEntityOwnerHandle { get; }

		public List<XYZ> ActualBox
		{
			get
			{
				return this.m_lstActualBox;
			}
		}

		public XYZ OrgPos { get; }

		public double ActualHight
		{
			get
			{
				return this.m_lstActualBox[0].DistanceTo(this.m_lstActualBox[2]);
			}
		}

		public TextInfo(DwgTextInfo dwgTextInfo, string strLayerName, ImportInstance ImportIns)
		{
			this.UseText = dwgTextInfo.ItemName;
			this.UseHight = dwgTextInfo.Height;
			this.HostImportIns = ImportIns;
			this.UseLayerName = strLayerName;
			this.UseCadOrginObj = dwgTextInfo.Text;
			this.IsAttribute = (this.UseCadOrginObj is OdDbAttribute);
			this.GuidInCad = dwgTextInfo.Text.objectId().getHandle().ascii();
			this.UseCadEntityOwnerHandle = dwgTextInfo.Text.ownerId().getHandle().ascii();
			this.OrgPos = GeometryCommon.ConvetPointFromCadToRevit(dwgTextInfo.Positon, this.HostImportIns.GetTotalTransform());
			this.OrgPos.SetZ(0.0);
			foreach (OdGePoint3d cadPnt in dwgTextInfo.ActualBoungding)
			{
				XYZ xyz = GeometryCommon.ConvetPointFromCadToRevit(cadPnt, this.HostImportIns.GetTotalTransform());
				xyz.SetZ(0.0);
				this.m_lstActualBox.Add(xyz);
			}
			this.BoundingBoxCurve = this.GetBoungdingCurve();
		}

		public override Line GetBaseLine()
		{
			Line line = null;
			bool flag = this.m_lstActualBox.Count != 4;
			Line result;
			if (flag)
			{
				result = line;
			}
			else
			{
				try
				{
					line = Line.CreateBound(this.m_lstActualBox[2], this.m_lstActualBox[3]);
				}
				catch (Exception)
				{
				}
				result = line;
			}
			return result;
		}

		public override XYZ GetHightDirection()
		{
			bool flag = this.m_lstActualBox.Count != 4;
			XYZ result;
			if (flag)
			{
				result = null;
			}
			else
			{
				result = this.m_lstActualBox[0] - this.m_lstActualBox[2];
			}
			return result;
		}

		protected List<Curve> GetBoungdingCurve()
		{
			List<Curve> list = new List<Curve>();
			try
			{
				Line item = Line.CreateBound(this.m_lstActualBox[2], this.m_lstActualBox[0]);
				list.Add(item);
				Line item2 = Line.CreateBound(this.m_lstActualBox[0], this.m_lstActualBox[1]);
				list.Add(item2);
				Line item3 = Line.CreateBound(this.m_lstActualBox[1], this.m_lstActualBox[3]);
				list.Add(item3);
				Line item4 = Line.CreateBound(this.m_lstActualBox[3], this.m_lstActualBox[2]);
				list.Add(item4);
			}
			catch (Exception)
			{
				return null;
			}
			return list;
		}

		private List<XYZ> m_lstActualBox = new List<XYZ>();
	}
}
